// 添加请求拦截器
let baseURL = 'http://www.itcbc.com:8080';
axios.defaults.baseURL = baseURL;
axios.interceptors.request.use(function (config) {
  let url = config.url;
  if (url.includes('/my/')) {
    config.headers['Authorization'] = localStorage.getItem('token');
  }
  return config;
}, function (error) {

  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  let {
    status,
    message
  } = response.data;
  if (status === 1) {
    layer.msg(message)
  }
  return response;
}, function (error) {

  // console.log(error.response);
  let {
    status,
    message
  } = error.response.data;
  if (status === 1 && message === '身份认证失败！')
    localStorage.removeItem('token');
  location.href = './login.html';
  layer.msg(message);
  return Promise.reject(error);
});